package com.liuxvru.project.system.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.ProjectAttachment;
import com.liuxvru.project.service.IProjectAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目附件Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/project/projectAttachment")
public class ProjectAttachmentController extends BaseController {
    @Autowired
    private IProjectAttachmentService projectAttachmentService;

    /**
     * 查询项目附件列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectAttachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectAttachment projectAttachment) {
        startPage();
        List<ProjectAttachment> list = projectAttachmentService.selectProjectAttachmentList(projectAttachment);
        return getDataTable(list);
    }

    /**
     * 导出项目附件列表
     */
    @PreAuthorize("@ss.hasPermi('project:projectAttachment:export')")
    @Log(title = "项目附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectAttachment projectAttachment) {
        List<ProjectAttachment> list = projectAttachmentService.selectProjectAttachmentList(projectAttachment);
        ExcelUtil<ProjectAttachment> util = new ExcelUtil<ProjectAttachment>(ProjectAttachment.class);
        util.exportExcel(response, list, "项目附件数据");
    }

    /**
     * 获取项目附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:projectAttachment:query')")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId) {
        return success(projectAttachmentService.getById(attachmentId));
    }

    /**
     * 新增项目附件
     */
    @PreAuthorize("@ss.hasPermi('project:projectAttachment:add')")
    @Log(title = "项目附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectAttachment projectAttachment) {
        return toAjax(projectAttachmentService.save(projectAttachment));
    }

    /**
     * 修改项目附件
     */
    @PreAuthorize("@ss.hasPermi('project:projectAttachment:edit')")
    @Log(title = "项目附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectAttachment projectAttachment) {
        return toAjax(projectAttachmentService.updateById(projectAttachment));
    }

    /**
     * 删除项目附件
     */
    @PreAuthorize("@ss.hasPermi('project:projectAttachment:remove')")
    @Log(title = "项目附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long[] attachmentIds) {
        return toAjax(projectAttachmentService.removeById(attachmentIds));
    }
}
